
import java.util.ArrayList;

/*
 * Represents an action that results in a game state.
 */
public class group1_KalahAction {
	// This is the game move that resulted in this game state ( 0 through 5 )
	public int game_move;
	// This is the game state that was prior to this game state
	public KalahPieGameState parent;
	// This is the game state that was the result of the game move
	public KalahPieGameState state;
	// This is the evaluation score
	public int score;
	
	/*
	 * Generate all of the possible actions for a given game state
	 */
	public static group1_KalahAction[] get_possible_actions( KalahPieGameState state ) {
		ArrayList<group1_KalahAction> actions_array = new ArrayList<group1_KalahAction>();
		// Loop through all of the possible moves and see if they are valid.
		// If the move is valid, create a copy of the game state and play that move
		// on the copy.
		for( int game_move = -1; game_move < 6; game_move++ ) {
			if( state.validMove( game_move ) ) {
				try {
					group1_KalahAction action = new group1_KalahAction();
					// Create a copy of the current game state that will be the resulting game state
					KalahPieGameState resulting_state = (KalahPieGameState)state.copy();
					// Play the move on the copied state to get the resulting state
					resulting_state.play(game_move);
					// Store this data in the action object
					action.game_move = game_move;
					action.parent = state;
					action.state  = resulting_state;
					// Add this action to the array
					actions_array.add( action );
				} catch( Exception e) {
					// Just continue;
				}
			}
		}
		// Return a Java array [] instead of an ArrayList to reduce memory overhead
		group1_KalahAction action_list[] = new group1_KalahAction[ actions_array.size() ];
		actions_array.toArray(action_list);
		return action_list;
	}
}
